package ontology.concepts.vo;

import javax.persistence.CascadeType;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

import ontology.concepts.general.INorm;

@Entity
@NamedQueries(
		{
			@NamedQuery(name = "VONorm.findAll", query = "SELECT n from VONorm n"),
		}
)
public class VONorm implements INorm{

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int normId;
	
	private String name;
	private String contract_type;
	private String description;
	
	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Antecedent antecedent; //Antecedente de uma norma
	
	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Consequent consequent; //consequente da norma
	
	public int getNormId() {
		return normId;
	}

	public void setNormId(int normId) {
		this.normId = normId;
	}
	
	
	public Antecedent getAntecedent() {
		return antecedent;
	}

	public void setAntecedent(Antecedent antecedent) {
		this.antecedent = antecedent;
	}

	public Consequent getConsequent() {
		return consequent;
	}

	public void setConsequent(Consequent consequent) {
		this.consequent = consequent;
	}
	 
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;		
	}

	
	public String getContract_type() {
		return contract_type;
	}

	public void setContract_type(String contract_type) {
		this.contract_type = contract_type;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public void setDescription(String description) {
		this.description = description;		
	}

	
	
	@Override
	public String toString() {
		return "VONorm [normId=" + normId + ", name=" + name + ", description="
				+ description + ", antecedent=" + antecedent.toString() + ", consequent="
				+ consequent.toString() + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((antecedent == null) ? 0 : antecedent.hashCode());
		result = prime * result
				+ ((consequent == null) ? 0 : consequent.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + normId;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		VONorm other = (VONorm) obj;
		if (antecedent == null) {
			if (other.antecedent != null)
				return false;
		} else if (!antecedent.equals(other.antecedent))
			return false;
		if (consequent == null) {
			if (other.consequent != null)
				return false;
		} else if (!consequent.equals(other.consequent))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (normId != other.normId)
			return false;
		return true;
	}
	
	@Override
	public VONorm clone(){
		VONorm norm = new VONorm();
		norm.setContract_type(new String(contract_type));
		if(description != null)
			norm.setDescription(new String(description));
		norm.setName(new String(name));
		norm.setNormId(normId);
		norm.setAntecedent(antecedent.clone());
		norm.setConsequent(consequent.clone());
		return norm;
	}
}
